﻿using System.Collections;
using System.Collections.Generic;
using PEProtocol;
using UnityEngine;
using UnityEngine.UI;

/**
 * 引导对话界面
 */

public class GuideWnd : WindowRoot{

    public Text txtName;
    public Text txtContent;
    public Image charImg;

    private AutoGuideCfg curGuideCfg;

    private PlayerData playerData;
    
    private string[] dialogArr;
    private int index;
    
    protected override void InitWnd(){
        base.InitWnd();
        curGuideCfg = MainCitySys.Instance.GetCurTaskData();
        dialogArr = curGuideCfg.dialogArr.Split('#');
        index = 1;
        playerData = GameRoot.Instance.PlayerData;
        SetTalk();
    }


    private void SetTalk(){
        string[] talkArr = dialogArr[index].Split('|');
        if (talkArr[0] == "0"){
            //自己
            SetSprite(charImg, PathDefine.SelfIcon);
            SetText(txtName, playerData.name);
        }
        else{
            //对话的npc
            switch (curGuideCfg.npcID){
                case 0:
                    SetSprite(charImg, PathDefine.WiseManIcon);
                    SetText(txtName, "智者");
                    break;
                case 1:
                    SetSprite(charImg, PathDefine.GeneralIcon);
                    SetText(txtName, "将军");
                    break;
                case 2:
                    SetSprite(charImg, PathDefine.ArtisanIcon);
                    SetText(txtName, "工匠");
                    break;
                case 3:
                    SetSprite(charImg, PathDefine.TraderIcon);
                    SetText(txtName, "商人");
                    break;
                default:
                    SetSprite(charImg, PathDefine.GuideIcon);
                    SetText(txtName, "yunnier");
                    break;
            }
        }
        charImg.SetNativeSize();
        SetText(txtContent, talkArr[1].Replace("$name", playerData.name));
    }

    public void ClickNextBtn(){
        audioSvc.PlayUIMusic(Constants.UIClickBtn);
        index++;
        if (index == dialogArr.Length){
            //TODO 发送任务引导完成信息
            GameMsg msg = new GameMsg{
                cmd = (int)CMD.ReqGuide,
                reqGuide = new ReqGuide{
                    guideid = curGuideCfg.ID
                }
            };
            netSvc.SendMsg(msg);
            SetWndState(false);
        }
        else{
            SetTalk();
        }
    }
    
}
